﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Globalization;

public partial class UserControl_ControlHistoryViewer : System.Web.UI.UserControl
{
    private ClassExecute.ClassExecute executer;
    string str = webapp4U.Configuration.CurrentConnectionString;
    string error = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            txtFromDate.Text = DateTime.Now.AddDays(-1).ToString("dd/MM/yyyy");
            txtToDate.Text = DateTime.Now.ToString("dd/MM/yyyy");
            LoadGrid();
        }
    }
    private void LoadGrid()
    {
        executer = new ClassExecute.ClassExecute();
        int flag = 0;
        if (chkFromDateToDate.Checked)
        {
            flag = 1;
        }
        try
        {
            DateTime FromDate = new DateTime();
            DateTime.TryParse( txtFromDate.Text, out FromDate);
            string from = string.Empty;
            string to = string.Empty;
            from=string.Format("{0:yyyy-MM-dd}", FromDate);
            DateTime ToDate = new DateTime();
            DateTime.TryParse(txtToDate.Text, out ToDate);
            to=string.Format("{0:yyyy-MM-dd}", ToDate.AddDays(1));

            DataTable dt = executer.Get_Data_DataTable(str, ref error, "D_History_Search", CommandType.StoredProcedure,
                 new SqlParameter("@Action", drlAction.SelectedValue.ToString()),
                 new SqlParameter("@FromDate", from),
                 new SqlParameter("@ToDate", to),
                 new SqlParameter("@flag", flag));

            if (dt.Rows.Count == 0)
            {
                grvIntxd.DataSource = null;
            }
            else
            {
                grvIntxd.DataSource = dt;
            }
            grvIntxd.DataBind();
        }
        catch (Exception ex)
        {

            string method = System.Reflection.MethodBase.GetCurrentMethod().Name;
            executer.WriteErrorLog(Server.MapPath(webapp4U.Globals.LogUrl()), ex.Message, method);
        }
    }
    protected void imgBtnAdd_Click(object sender, ImageClickEventArgs e)
    {
        LoadGrid();
    }
    protected void grvIntxd_PageIndexChanging1(object sender, GridViewPageEventArgs e)
    {
        grvIntxd.PageIndex = e.NewPageIndex;
        LoadGrid();
    }

    protected void chkFromDateToDate_CheckedChanged(object sender, EventArgs e)
    {
        txtFromDate.Enabled = chkFromDateToDate.Checked;
        txtToDate.Enabled = chkFromDateToDate.Checked;
    }
}
